﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace DAL
{
    public class DataProvide
    {
        private static string _connectionString = @"Data Source=GHOSTVIE-398659;Initial Catalog=QuanLyWebsite;Integrated Security=True";
        protected SqlConnection connection;
        protected SqlCommand command;

        public static string ConnectionString
        {
            get { return DataProvide._connectionString; }
            set { DataProvide._connectionString = value; }
        }

        public void Connect()
        {
            connection = new SqlConnection(_connectionString);
            connection.Open();
        }

        protected void Disconnect()
        {
            connection.Close();
        }

        protected SqlDataReader ExecuteReader(string sqlString)
        {
            command = new SqlCommand(sqlString, connection);
            return command.ExecuteReader();
        }

        protected void ExecuteNonQuery(string sqlString)
        {
            command = new SqlCommand(sqlString, connection);
            command.ExecuteNonQuery();
        }

        protected object ExecuteScalar(string sqlString)
        {
            command = new SqlCommand(sqlString, connection);
            return command.ExecuteScalar();
        }

        protected virtual object GetDataRowFromDataReader(SqlDataReader dr)
        {
            return null;
        }

        protected string ConvertBytesToString(byte[] photo_aray)
        {
            string imgStr = "0x" + BitConverter.ToString(photo_aray).Replace("-", string.Empty);
            return imgStr;
        }
    }
}
